require 'rubygems'
require "rake"
require "rake/clean"
require "albacore"
require "FileUtils"
require "erb"

directory "Out"
directory "Out/Release"
directory "Release"

@version = "0.1.1"

task :default => :zipPackage do
end

file 'Out/valyjs_version.js' => ['src/valyjs.js', 'Out'] do |t|
	content = nil
	File.open(t.prerequisites[0], 'r') { |f| content = f.read }
	result = ERB.new(content).result
	File.open(t.name, 'w') { |f| f.write(result) }
end

task :minimize => ['Out/valyjs_version.js', 'Out/Release'] do
	system "java -jar lib/Closure_compiler/compiler.jar --js Out/valyjs_version.js --js_output_file Out/valyjs_min.js"
end

desc "Coppy all release resources to the output direcotry"
output :package => [:minimize, 'Release'] do |out|
	out.to "Out/Release"
	out.from File.dirname(__FILE__)
	out.file "Out/valyjs_version.js", :as => "valyjs_" + @version + ".js"
	out.file "Out/valyjs_min.js", :as => "valyjs_" + @version + "_min.js"
end

desc "Create zip package"
zip :zipPackage => :package do |zip|
	zip.directories_to_zip "Out/Release"
	zip.output_file = "ValyJS_" + @version + ".zip"
	zip.output_path = "Release"
end